package com.kzc.controller.user;

import com.kzc.base.ResponseWrapper;
import com.kzc.bean.UserBean;
import com.kzc.mapper.user.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.RequestWrapper;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired(required = false)
    UserMapper userMapper;

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ResponseWrapper<UserBean> userLogin(HttpServletRequest request){

       // httpServletRequest.getParameter()
        ResponseWrapper<UserBean> responseWrapper = new ResponseWrapper<>();
        String phone = request.getParameter("phone");
        String pwd = request.getParameter("password");

        if(phone == null || phone.isEmpty()){
            responseWrapper.setStatus(-1);
            responseWrapper.setMessage("手机号为空!");
            return responseWrapper;
        }

        if(pwd == null || pwd.isEmpty()){
            responseWrapper.setStatus(-1);
            responseWrapper.setMessage("密码为空!");
            return responseWrapper;
        }

        UserBean userBean = userMapper.userLogin(phone);

        //没有用户
        if(userBean == null){
            responseWrapper.setStatus(-1);
            responseWrapper.setMessage("请先注册");
            return responseWrapper;
        }


        responseWrapper.setStatus(200);
        responseWrapper.setMessage("成功");
        responseWrapper.setData(userBean);
        return responseWrapper;
    }


}
